<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>书城首页</title>
<link rel="stylesheet" href="/static/css/style.css">
</head>
<body>
	
	<div id="header">
			<img class="logo_img" alt="" src="/static/img/logo.gif" >
			<span class="wel_word">网上书城</span>
			{{if .IsLogin}}
			<div>
				<span>欢迎<span class="um_span">{{.Username}}</span>光临尚硅谷书城</span>
				<a href="/toCart">购物车</a>
				<a href="/toMyOrders">我的订单</a>
				<a href="/logout">注销</a>&nbsp;&nbsp;
				<a href="/main">返回</a>
			</div>
			{{else}}
			<div>
				<a href="/login">登录</a> | 
				<a href="/register">注册</a> &nbsp;&nbsp;
				<a href="/toCart">购物车</a>
				<a href="/pages/manager/manager.html">后台管理</a>
				<a href="/main">返回</a>
			</div>
			{{end}}
	</div>
	
	<div id="main">
		<div id="book">
			<div class="book_cond">
				<!-- 
					当发送post请求时，是通过请求体来传递请求参数，所以在Servlet中就不能获取到请求参数了
					所以这里最好不要使用post请求，改用get请求
					但是get请求会自动覆盖action属性中的参数，所以当使用get请求时，我们只能通过表单项来传递请求参数
				 -->
				<form action="/getBookByPrice" method="post">
					<input type="hidden" name="method" value="findBookByPrice" />
					价格：<input type="text" name="minPrice" value=""> 元 - 
						<input value="" type="text" name="maxPrice"> 元 
					<input type="submit" value="查询" />
				</form>
			</div>
			<div style="text-align: center">
				
				
						<span id="count_span" style="display:none">购物车中还没有商品！</span>
					
				
				
				<div id="cartBar" >
					您刚刚将<span style="color: red" id="cart"></span>加入到了购物车中
					
					
				</div>
				
				<div id="title_info"></div>
			</div>
			
			{{range .Books}}
						<div class="b_list">
							<div class="img_div">
								<img class="book_img" alt="" src="{{.Img_path}}" />
							</div>
							<div class="book_info">
								<div class="book_name">
									<span class="sp1">书名:</span>
									<span class="sp2">{{.Title}}</span>
								</div>
								<div class="book_author">
									<span class="sp1">作者:</span>
									<span class="sp2">{{.Author}}</span>
								</div>
								<div class="book_price">
									<span class="sp1">价格:</span>
									<span class="sp2">￥{{.Price}}</span>
								</div>
								<div class="book_sales">
									<span class="sp1">销量:</span>
									<span class="sp2">{{.Sales}}</span>
								</div>
								<div class="book_amount">
									<span class="sp1">库存:</span>
									<span class="sp2">{{.Stock}}</span>
								</div>
								<div class="book_add">
									{{if .Stock}}
									<button id="{{.Id}}" class="addCart">加入购物车</button>
									{{else}}
									<span style="color:red">小二正在加急补货中</span>
									{{end}}
								</div>
							</div>
						</div>
			{{end}}		
			
		
			
			
			
		</div>
		
		<div id="page_nav">
			
			{{if .IsHasPrev}}
			<a href="/getBookByPrice?pageNo=1&minPrice={{.MinPrice}}&maxPrice={{.MaxPrice}}">首页</a>
			<a href="/getBookByPrice?pageNo={{.GetPrevPage}}&minPrice={{.MinPrice}}&maxPrice={{.MaxPrice}}">上一页</a>
			{{end}}
			
						当前第{{.PageNo}}页
						共{{.PageCount}}页，{{.RecordCount}}条记录
			{{if .IsHasNext}}	
			<a href="/getBookByPrice?pageNo={{.GetNextPage}}&minPrice={{.MinPrice}}&maxPrice={{.MaxPrice}}">下一页</a>
			<a href="/getBookByPrice?pageNo={{.PageCount}}&minPrice={{.MinPrice}}&maxPrice={{.MaxPrice}}">末页</a>
			{{end}}
			 到第<input value="" name="pn" id="pn_input"/>页
			<input id="pn_btn" type="button" value="确定">
			
		</div>
	
	</div>
	
	<div id="bottom">
		<span>
			尚硅谷书城.Copyright &copy;2015
		</span>
	</div>
</body>
<script src="/static/script/jquery-1.7.2.js"></script>
<script type="text/javascript">
	$(function(){
		$("#cartBar").hide()

		$("#pn_btn").click(function(){
			var page = $("#pn_input").val()
			window.location="/getBookByPrice?pageNo="+page+"&minPrice={{.MinPrice}}&maxPrice={{.MaxPrice}}"
		})

		$(".addCart").click(function(){
			var bookid=$(this).attr("id")
			var url="/addBookToCart"
			var param={"bookid":bookid}
			$.post(url,param,function(res){
				if (res=="请先登录"){
					location="/login"
				}else{
					$("#cart").text(res)
					$("#cartBar").fadeIn()
				}
				
			})
		})
	})

	

</script>
</html>